const IS_PROD = ["production", "prod"].includes(process.env.NODE_ENV);
const path = require("path"); //引入path模块
const defaultSettings = require("./src/settings.js");
function resolve(dir) {
  return path.join(__dirname, dir); //path.join(__dirname)设置绝对路径
}

const name = defaultSettings.title || "vue  Admin"; // page title

module.exports = {
  outputDir: process.env.outputDir,
  publicPath: process.env.NODE_ENV === "production" ? "./" : "/",
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: name
  },
  chainWebpack: config => {
    config.resolve.alias.set("@", resolve("./src"));
    //set第一个参数：设置的别名，第二个参数：设置的路径

    // set svg-sprite-loader
    config.module
      .rule("svg")
      .exclude.add(resolve("src/icons"))
      .end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]"
      })
      .end();

    // set preserveWhitespace
    config.module
      .rule("vue")
      .use("vue-loader")
      .loader("vue-loader")
      .tap(options => {
        options.compilerOptions.preserveWhitespace = true;
        return options;
      })
      .end();

    //兼容IE
    config.entry("main").add("babel-polyfill"); // main是入口js文件

    if (process.env.NODE_ENV === "production") {
      // 测试生产环境, 不压缩js代码
      if (process.env.VUE_APP_MODE === "test") {
        config.optimization.minimize(false);
      }
    }
  },

  devServer: {
    // overlay: {
    //   warnings: true,
    //   errors: true
    // },
    open: IS_PROD,
    https: false,
    hotOnly: false,
    port: 8080,
    proxy: {
      "/api": {
        // target: 'http://192.168.1.218:9083',
        target: "http://192.168.1.50:9091",
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true,
        pathRewrite: {
          "^/api": "/"
        }
      }
    }
  },

  lintOnSave: false
};
